﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
void Swap2(int* px, int* py)
{
	int tmp = 0;
	tmp = *px;
	*px = *py;
	*py = tmp;
}
int main()
{
	int a = 0;
	int b = 0;
	scanf("%d %d", &a, &b);
	printf("交换前：a = % d b = % d\n", a, b); 
	Swap2(&a, &b);
	printf("交换后：a = % d b = % d\n", a, b);
	return 0;
}




#if 0
void Swap1(int x, int y)
{
	int tmp = x;
	x = y;
	y = tmp;
}
int main()
{
	int a = 0;
	int b = 0;
	scanf("%d %d", &a, &b);
	Swap1(a, b);
	printf("交换前：a = % d b = % d\n", a, b);
	printf("交换后：a = % d b = % d\n", a, b);
	return 0;
}
int main()
{
	int arr[10] = { 1,2,3,4,5,67,7,8,9,10 };
	int* p = &arr[0];
	int i = 0;
	for (i = 0; i < 10; i++)
	{
		*(p++) = i;
	}
	//此时p已经越界了，可以把p置为NULL
	p = NULL;
	//下次使⽤的时候，判断p不为NULL的时候再使⽤
	//...
	p = &arr[0];//重新让p获得地址
	if (p != NULL) //判断
	{
		//...
	}
	return 0;
}
int main(void)
{
	int num = 10;
	int* p1 = &num;
	int* p2 = NULL;
	return 0;
}
int main(void)
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int* p = &arr[0];
	while (p < arr + sz)
	{
		printf("%d ", *p);
		p++;
	}
	return 0;
}
//int main(void)
//{
//	int a = 0;
//	int* pa = &a;
//	*pa = 100;
//	printf("%d\n", a);
//	return 0;
//}

int main(void)
{
	int a = 10;
	char ch = 'a';
	int* pa = &a;
	char* pb = &ch;
	printf("%d\n", sizeof(pa));
	printf("%d\n", sizeof(pa));
	return 0;
}
	int main(void)
{
	int a,b = 0x11223344;
	int* pa = &a;
	char* pb = &b;
	*pa = 0;
	*pb = 0;
	printf("%x\n", a);
	printf("%x\n", b);
	return 0;
}
int main(void)
{
	int n = 10;
	char* pc = (char*)&n;
	int* pi = &n;
	printf("%p\n", &n);
	printf("%p\n", pc);
	printf("%p\n", pc + 1);
	printf("%p\n", pi);
	printf("%p\n", pi + 1);
	return 0;
{
	int main(void)
	int a = 25;
	int* pa = &a;
	void* pb = &a;
	return 0;
}
{
	int m = 0;
	m = 20;//m是可以修改的

	const int n = 0;
	n = 20;//n是不能被修改的

	return 0;
}
{
	const int n = 20;
	int arr[n] = { 0 };
	return 0;
}
	const int n = 0;
	printf("n = %d\n", n);
	int* p = &n;
	*p = 20;
	printf("n = %d\n", n);
	const int a = 10;
	int b = 100;
	int* const p = &a;

	*p = 0;//ok
	p = &b;//error
for (int i = 0; i <= 9; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");	
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int* p = &arr[0];
	for (int i = 0; i < sz; i++)
	{
		printf("%d", *p);
		p++;
		int arr[10] = { 0 };
		printf("%d\n", &arr[9] - &arr[0]);
	}	
	char arr[] = "abcdefgh";
	int len = strlen(arr);
	printf("%d\n", len);
	int my_strlen(char* p)
	{
		int count = 0;
		while (*p != '\0')
		{
			count++;
			p++;
		}
		return count;
		int my_strlen(char* p)
		{
			char* p1 = p;
			while (*p != '\0')
			{
				p++;
			}
			return p - p1;
		}


		int main()
		{
			char arr[] = "abcdefgh";
			int len = my_strlen(arr);
			printf("%d\n", len);
			return 0;
		}

	}

	int main()
	{
		int* p;//局部变量指针未初始化，默认为随机值
		*p = 20;
		return 0;
	}
	int main()
	{
		int arr[10] = { 0 };
		int* p = &arr[0];
		int i = 0;
		for (i = 0; i <= 11; i++)
		{
			//当指针指向的范围超出数组arr的范围时，p就是野指针
			*(p++) = i;
		}
		return 0;

		int* test()
		{
			int n = 100;
			return &n;
		}
		int main()
		{
			int* p = test();
			printf("%d\n", *p);
			return 0;
		}
	}
#endif
